<h1 id="systemctl">systemctl</h1>
<p>系统服务管理器指令</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>systemctl命令</strong> 是系统服务管理器指令，它实际上将 service 和 chkconfig 这两个命令组合到一起。</p>
<table>
<colgroup>
<col style="width: 33%" />
<col style="width: 33%" />
<col style="width: 33%" />
</colgroup>
<thead>
<tr class="header">
<th>任务</th>
<th>旧指令</th>
<th>新指令</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>使某服务自动启动</td>
<td>chkconfig –level 3 httpd on</td>
<td>systemctl enable httpd.service</td>
</tr>
<tr class="even">
<td>使某服务不自动启动</td>
<td>chkconfig –level 3 httpd off</td>
<td>systemctl disable httpd.service</td>
</tr>
<tr class="odd">
<td>检查服务状态</td>
<td>service httpd status</td>
<td>systemctl status httpd.service （服务详细信息） systemctl is-active httpd.service （仅显示是否 Active)</td>
</tr>
<tr class="even">
<td>显示所有已启动的服务</td>
<td>chkconfig –list</td>
<td>systemctl list-units –type=service</td>
</tr>
<tr class="odd">
<td>启动某服务</td>
<td>service httpd start</td>
<td>systemctl start httpd.service</td>
</tr>
<tr class="even">
<td>停止某服务</td>
<td>service httpd stop</td>
<td>systemctl stop httpd.service</td>
</tr>
<tr class="odd">
<td>重启某服务</td>
<td>service httpd restart</td>
<td>systemctl restart httpd.service</td>
</tr>
</tbody>
</table>
<h3 id="实例">实例</h3>
<div class="sourceCode" id="cb1"><pre><code class="language-bash"><a class="sourceLine" id="cb1-1" data-line-number="1"><span class="ex">systemctl</span> start nfs-server.service . <span class="co"># 启动nfs服务</span></a>
<a class="sourceLine" id="cb1-2" data-line-number="2"><span class="ex">systemctl</span> enable nfs-server.service <span class="co"># 设置开机自启动</span></a>
<a class="sourceLine" id="cb1-3" data-line-number="3"><span class="ex">systemctl</span> disable nfs-server.service <span class="co"># 停止开机自启动</span></a>
<a class="sourceLine" id="cb1-4" data-line-number="4"><span class="ex">systemctl</span> status nfs-server.service <span class="co"># 查看服务当前状态</span></a>
<a class="sourceLine" id="cb1-5" data-line-number="5"><span class="ex">systemctl</span> restart nfs-server.service <span class="co"># 重新启动某服务</span></a>
<a class="sourceLine" id="cb1-6" data-line-number="6"><span class="ex">systemctl</span> list-units --type=service <span class="co"># 查看所有已启动的服务</span></a></code></pre></div>
<p>开启防火墙22端口</p>
<pre><code class="language-bash">iptables -I INPUT -p tcp --dport 22 -j accept</code></pre>
<p>如果仍然有问题，就可能是SELinux导致的</p>
<p>关闭SElinux：</p>
<p>修改<code>/etc/selinux/config</code>文件中的<code>SELINUX=&quot;&quot;</code>为disabled，然后重启。</p>
<p>彻底关闭防火墙：</p>
<div class="sourceCode" id="cb3"><pre><code class="language-bash"><a class="sourceLine" id="cb3-1" data-line-number="1"><span class="ex">sudo</span> systemctl status firewalld.service</a>
<a class="sourceLine" id="cb3-2" data-line-number="2"><span class="ex">sudo</span> systemctl stop firewalld.service          </a>
<a class="sourceLine" id="cb3-3" data-line-number="3"><span class="ex">sudo</span> systemctl disable firewalld.service</a></code></pre></div>
<!-- Linux命令行搜索引擎：https://jaywcjlove.github.io/linux-command/ -->
